package kr.co.tomatosystem.pde.tools.internal.marker;

import kr.co.tomatosystem.pde.tools.internal.build.BuilderPropertyPage;

import org.eclipse.core.resources.IMarker;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.jface.preference.PreferenceManager;
import org.eclipse.jface.preference.PreferenceNode;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.PropertyPage;

public class ReConfigureSetting implements IMarkerResolution {

	@Override
	public String getLabel() {
		return "Configure Resource Accessor generation settings.";
	}

	@Override
	public void run(final IMarker marker) {
		Display.getDefault().syncExec(new Runnable() {
			@Override
			public void run() {
				runInUIThread(marker);
			}
		});
	}

	protected void runInUIThread(IMarker marker) {
		IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		if (activeWorkbenchWindow == null) {
			return;
		}

		PropertyPage page = new BuilderPropertyPage();
		page.setElement(marker.getResource().getProject());

		PreferenceManager manager = new PreferenceManager();
		PreferenceNode node = new PreferenceNode("root", page);
		manager.addToRoot(node);
		page.setTitle("Resource Accessor");
		PreferenceDialog dialog = new PreferenceDialog(activeWorkbenchWindow.getShell(), manager);
		dialog.create();
		dialog.open();

	}

}
